/**
 * User 相关
 */

import service from "@/utils/request";

enum API {
  getUserList = '/admin/acl/user',
  deleteUser = '/admin/acl/user/remove',

  addUser = '/admin/acl/user/save',

  updateUser = '/admin/acl/user/update',

  batchDeleteUser = '/admin/acl/user/batchRemove',

  getToAssign = '/admin/acl/user/toAssign',

  // 分配角色
  doAssign = '/admin/acl/user/doAssign'
}

// 获取用户列表
export const reqGetUserList = (page: number, limit: number, username: string) => service.get(`${API.getUserList}/${page}/${limit}`, {
  params: {
    username
  }
})

// 删除用户
export const reqDeleteUser = (id: string) => service.delete(`${API.deleteUser}/${id}`)

// 批量删除用户
export const reqBatchDeleteUser = (idList: string[]) => service.delete(API.batchDeleteUser, {
  data: idList
})

// 添加用户
export const reqAddUser = (userInfo) => service.post(API.addUser, userInfo)

// 修改用户
export const reqUpdateUser = (userInfo) => service.put(API.updateUser, userInfo)

// 获取角色列表
export const reqToAssign = (adminId) => service.get(`${API.getToAssign}/${adminId}`)

// 分配角色
export const reqDoAssign = (userId, roleId) => service.post(API.doAssign, {}, {
  params: {
    userId,
    roleId
  }
})